﻿//-----------------------------------------------------------------------
// <copyright file="ScanningService.cs" company="FastNET Services">
//     Copyright (c) 2007-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;
using FastNET.CleanAct.Client.ClientEngine.Jobs;
using FastNET.CleanAct.Client.Interfaces.Jobs;
using FastNET.CleanAct.Client.Interfaces.Services;
using FastNET.CleanAct.Client.Interfaces.TaskProcessing.Scanners;
using FastNET.CleanAct.Client.Interfaces.Tasks;
using FastNET.CleanAct.Client.TaskProcessing.Basic.Scanners;

#endregion

namespace FastNET.CleanAct.Client.ClientEngine.Managers.Processing.Services
{
    /*
     * To Scan
     * Retrieve Configs
     * Determine Scanners
     * Perform Scans
     * Return List of Tasks
     */

    internal class ScanningService : IService
    {
        #region Variables

        private readonly List<IScanner> _scanners;

        #endregion

        #region CTor/DTor

        /// <summary>
        /// Initializes a new instance of the ScanningService class
        /// </summary>
        public ScanningService()
        {
            _scanners = new List<IScanner>
                        {
                            new SystemFileScanner(),
                            new RegistryScanner()
                        };
        }

        #endregion

        #region Public Collection Properties

        /// <summary>
        /// Gets or sets the list of all jobs that can be processed by the service
        /// </summary>
        public List<IJob> JobList { get; set; }

        #endregion

        #region Public Processing Methods

        /// <summary>
        /// Tells the service to process the list of jobs
        /// </summary>
        public void Process()
        {
            foreach (IScanner scanner in _scanners)
            {
                foreach (IJob job in JobList)
                {
                    job.ProcessedBy.Add(string.Format("{0} - {1}", scanner.ProcessorName, scanner.ProcessorDescription));

                    foreach (KeyValuePair<Guid, IJobAction> action in job.ActionList)
                    {
                        foreach (ITask task in scanner.PerformScan(action.Value, action.Key))
                        {
                            job.TaskList.Add(task);
                        }
                    }
                }
            }
        }

        #endregion
    }
}
